package com.epoint.juc.unsafecollection;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

public class Set2 {

    public static void main(String[] args) {
        // Exception in thread "24" java.util.ConcurrentModificationException
//        Set<String> set = new HashSet<>();

        Set<String> set = new CopyOnWriteArraySet<>();

        for (int i = 1; i <=30 ; i++) {
            new Thread(()->{
                set.add(UUID.randomUUID().toString().substring(0,5));
                System.out.println(set);
            },String.valueOf(i)).start();
        }
        System.out.println(set);
    }

}
